<?php

/*
 * ************************************************* 
 * Created on :2012-3-19 23:55:33
 * Encoding   :UTF-8
 * Description:
 * 
 * @Author @lqs <soso2501@gmail.com>
 * @WAP_WEIBO (C)1996-2099 SINA Inc. 
 * ************************************************
 */

define('ROOT_DIR', dirname(dirname(__FILE__)) . "/");
require_once(ROOT_DIR . 'lib/config.php');

function __autoload($name) {
    $plugins = array(
        'Smarty' => ROOT_DIR . 'lib/Smarty/Smarty.class.php',
    );
    if (isset($plugins[$name]))
        require_once($plugins[$name]);
    else if (file_exists(ROOT_DIR . 'lib/' . $name . ".php")) {
        require_once(ROOT_DIR . 'lib/' . $name . ".php");
    } else if (file_exists(ROOT_DIR . 'lib/' . $name . ".class.php")) {
        require_once(ROOT_DIR . 'lib/' . $name . ".class.php");
    } else if (file_exists(ROOT_DIR . 'class/' . $name . ".php")) {
        require_once(ROOT_DIR . 'class/' . $name . ".php");
    } else if (file_exists(ROOT_DIR . 'class/' . $name . ".class.php")) {
        require_once(ROOT_DIR . 'class/' . $name . ".class.php");
    }else
        throw new LException(ROOT_DIR . 'class/' . $name . ".php not find");
}

set_exception_handler('exception_handle');
set_error_handler('error_handle');

function error_handle($errorNo, $message, $filename, $lineNo) {
    if (error_reporting() != 0) {
        $type = 'error';
        switch ($errorNo) {
            case 2 :
                $type = 'warning';
                break;
            case 8 :
                $type = 'notice';
                break;
        }

        throw new LException('PHP ' . $type . ' in file ' . $filename . ' (' . $lineNo . '): ' . $message, 0);
    }
}

function exception_handle($e) {
    if ($e instanceof LException) {
        $e->show();
        exit();
    }

    print $e;
}

/* End of file init */




    